<template>
    <div>
        <top-bar></top-bar>
        <left-bar :datas='data'></left-bar>
        <div class="main">
            <div class="main-mains">
                <div class="main-content">
                    <div class="main-mains-top">
                        意见反馈
                    </div>
                    <div class="publicTable toLongTable">
                        <table class="head_table">
                            <tr>
                                <td width="5%">序号</td>
                                <td width='10%'>反馈时间</td>
                                <td width='12%'>用户实名</td>
                                <td width='7%'>用户类型</td>
                                <td width='10%'>用户手机号</td>
                                <td width='7%'>反馈类型</td>
                                <td width='12%'>反馈内容</td>
                                <td width='12%'>状态</td>
                                <td width='7%'>操作</td>
                            </tr>
                        </table>
                        <el-scrollbar>
                            <table class="content_table">
                                <tr v-for="(item,index) in listData" :key="index" :class="{active:index%2==1}">
                                    <td width="5%">{{index+1}}</td>
                                    <td width='10%'>{{item.create_time | times}}</td>
                                    <td width='12%'>{{item.name}}</td>
                                    <td width='7%'>{{item.rolename}}</td>
                                    <td width='10%'>{{item.mobile}}</td>
                                    <td width='7%' v-if="item.type==0">投诉</td>
                                    <td width='7%' v-else>建议</td>
                                    <td width='12%'>{{item.content}}</td>
                                    <td width='12%' v-if="item.status==0">未处理</td>
                                    <td width='12%' v-else>已处理</td>
                                    <td width='7%'>
                                        <span v-if='item.status==0' class="active" @click="clickClose(item.id)">关闭</span>
                                    </td>
                                </tr>
                            </table>
                        </el-scrollbar>
                    </div>
                    <div class="nodataTip" v-if="showNodataTip">
                        <i class="iconfont icon-zanwuneirong"></i>
                        <h5>暂无内容</h5>
                    </div>
                    <div class="orderBotom">
                        <div class="orderBotomRight">
                            <el-pagination @current-change="handleCurrentChange" :page-size="15" layout="total, prev, pager, next" :total='totalnum'>
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script>
import leftBar from "@/components/leftBar";
import topBar from "@/components/topBar";
import suggest from "@/api/suggest";

export default {
  components: {
    leftBar,
    topBar
  },
  data() {
    return {
      data: "suggest",
      pages: 1,
      listData: [],
      totalnum: 0,
      showNodataTip: false
    };
  },
  methods: {
    clickClose(id) {
      this.$confirm("是否处理当前反馈?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const options = {
            su_id: id,
            status: 1
          };
          suggest.handleSuggest(options).then(res => {
            if (res.code == 1) {
              this.$message({
                showClose: true,
                message: "已处理",
                type: "success"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    handleCurrentChange(val) {
      this.pages = val;
      this.getList();
    },
    getList() {
      this.showNodataTip = false;
      const options = {
        page: this.pages
      };
      suggest.getList(options).then(res => {
        if (res.code == 1) {
          this.listData = res.data.data;
          this.totalnum = res.data.total;
          if (!res.data.total) {
            this.showNodataTip = true;
          }
        }
      });
    }
  },
  mounted() {
    this.getList();
  },
  filters: {
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    }
  }
};
</script>

<style lang='less'>
</style>
